package com.archermind.boc.xml.parser.impl;

import com.archermind.boc.Logger;
import com.archermind.boc.dal.business.IDispatch;
import com.archermind.boc.xml.parser.IProcessorHelper;
import com.archermind.boc.xml.parser.Processor;

public abstract class BaseProcessor implements Processor {
	private final static Logger logger = Logger.getLogger(BaseProcessor.class.getName());
	private IDispatch dispatch;
	private IProcessorHelper helper;

	public IProcessorHelper getHelper() {
		return helper;
	}

	public void setHelper(IProcessorHelper helper) {
		this.helper = helper;
	}

	public IDispatch getDispatch() {
		return dispatch;
	}

	public void setDispatch(IDispatch dispatch) {
		this.dispatch = dispatch;
	}

	public void process(String sessionID, String xml) {
		Object object = null;
		try {
			object = parse(sessionID, xml);
		} catch (Exception e) {
			logger.warning("error when parse xml!", e);
		}
		if (object != null) {
			doBack(object);
		}
	}

	public abstract Object parse(String sessionID, String xml) throws Exception;

	public abstract void doBack(Object object);
}
